import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'root',
    redirect: '/home',
    component:HomeView,
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
    redirect: "/home/shouye",
    children: [
      {
        path: 'shouye',
        name: 'shouye',
        component: () => import('../views/ShouYeView.vue'),
      },
      {
        path: 'fenlei',
        name: 'fenlie',
        component: () => import('../views/FenLei.vue'),
      },
      {
        path: 'biaoqian',
        name: 'biaoqian',
        component: () => import('../views/BiaoQian.vue'),
      },
      {
        path: 'guidang',
        name: 'guidang',
        component: () => import('../views/GuiDang.vue'),
      },
      {
        path: 'shouxiang',
        name: 'shouxiang',
        component: () => import('../views/ShouXing.vue'),
      },
      {
        path: 'fenxiang',
        name: 'fenxiang',
        component: () => import('../views/FenXiang.vue'),
      },
    ]
  },
  {
    path: '/about',
    name: 'about',

    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',

    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/wenbiaoji',
    name: 'wenbiaoji',

    component: () => import('../views/WenBiaoji.vue')
  },
  {
    path: '/xiewen',
    name: 'xiewen',

    component: () => import('../views/XieWen.vue')
  },
  {
    path: '/houtai',
    name: 'houtai',
    component: () => import('../views/HoutaiView.vue'),
    redirect:"/houtai/yibiao",
    children: [
      {
        path: 'yibiao',
        name: 'yibiao',
        components: {
          default: () => import('../views/YiBiao.vue'),
          
        }
      },
      {
        path: 'wenzhang',
        name: 'wenzhang',
        components: {
          default: () => import('../views/WenZhang.vue'),
        }
      },
      {
        path: 'fenguan',
        name: 'fenguan',
        components: {
          default: () => import('../views/FenGuan.vue'),
        }
      },
      {
        path: 'biaoguan',
        name: 'biaoguan',
        components: {
          default: () => import('../views/BiaoGuan.vue'),
        }
      },
      {
        path: 'shezhi',
        name: 'shezhi',
        components: {
          default: () => import('../views/SheZhi.vue'),
        }
      },
    ]


  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {


  if (to.path == '/login') {

    return next()
  }

  if (localStorage.getItem("token")) {
    next();
  } else {
    next('/login')
  }
})
export default router
